﻿using System;
using System.Windows;

using SBPweb.GoogleDataAPI.Client.Connector.Services;

namespace WpfTestApp
{
    /// <summary>
    /// Interaction logic for App.xaml
    /// </summary>
    public partial class App : Application
    {

        protected override void OnStartup(StartupEventArgs e)
        {
            //ServiceConnector.UriOverriding += new EventHandler<ServiceConnector.UriOverrideEventArgs>(ServiceConnector_UriOverriding);
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(CurrentDomain_UnhandledException);
            base.OnStartup(e);
        }

        private void CurrentDomain_UnhandledException(object sender, UnhandledExceptionEventArgs e)
        {
        }

        private void ServiceConnector_UriOverriding(object sender, ServiceConnector.UriOverrideEventArgs e)
        {
            string dnsSafeHost = ServiceConnector.DnsSafeHost;
            string localPath = e.Uri.LocalPath;

            dnsSafeHost = "gdata.sbpweb.hu";
            localPath = localPath.Substring(localPath.IndexOf("/Services"));

            string host = string.Format("{0}://{1}:{2}{3}", e.Uri.Scheme, dnsSafeHost, e.Uri.Port, localPath);
            e.Uri = new Uri(host);
        }

    }

}